/* Copyright (c) 2009 Byron Adams <byron.adams54@gmail.com>
   See the file LICENSE for licensing information. */

translator.languages = {
  
  /**
   * Returns an object containing meta data for the given language.
   * Languages can be identified either by Language Codes (Based on ISO 639-1),
   * English Names (eg "FRENCH"), or a custom alias.
   * see the list array below for a reference. 
   *
   * @example translator.languages.find("en")
   * @result {name : "ENGLISH", code : "en", direction "LTR", charset : "UTF8"}
   *
   * @example translator.languages.find("German")
   * @result {name : "GERMAN", code : "de", direction "LTR", charset : "UTF8"}
   *
   * @name translator.language.find()
   * @param String query
   */  
  find : function (query) {
    
    this.cache = this.cache || {};
    
    if (query in this.cache) 
      return this.list[ this.cache[query] ];
    
    for(var key = 0, length = this.list.length; key < length; key++) {
      if (this.list[key].name == query.toUpperCase() || this.list[key].code == query.toLowerCase()) {
        this.cache[query] = key;
        return this.list[key];
      }
    }
    
    return false;
  },
  
  /**
   * Creates a language alias for the language specified.
   *
   * @example translator.languages.alias("en", "My_Alias");
   *
   * @name translator.language.alias()
   * @param String lang
   * @param String alias
   */  
  alias : function (lang, alias) {
    if ( this.find(lang) ) this.cache[alias] = this.cache[lang];
  },
  
  list : [
    {name:"AFRIKAANS", code:"af", direction:"LTR", charset:"UTF8"},
    {name:"ALBANIAN", code:"sq", direction:"LTR", charset:"UTF8"},
    {name:"ARABIC", code:"ar", direction:"RTL", charset:"UTF8"},
    {name:"BASQUE", code:"eu", direction:"LTR", charset:"UTF8"},
    {name:"BELARUSIAN", code:"be", direction:"LTR", charset:"UTF8"},
    {name:"BULGARIAN", code:"bg", direction:"LTR", charset:"UTF8"},
    {name:"BRETON", code:"br", direction:"LTR", charset:"UTF8"},
    {name:"CATALAN", code:"ca", direction:"LTR", charset:"UTF8"},
    {name:"CHINESE", code:"zh", direction:"LTR", charset:"UTF8"},
    {name:"CHINESE_SIMPLIFIED", code:"zh-hans", direction:"LTR", charset:"UTF8"},
    {name:"CHINESE_TRADITIONAL", code:"zh-hant", direction:"LTR", charset:"UTF8"},
    {name:"CROATIAN", code:"hr", direction:"LTR", charset:"UTF8"},
    {name:"CZECH", code:"cs", direction:"LTR", charset:"UTF8"},
    {name:"DANISH", code:"da", direction:"LTR", charset:"UTF8"},
    {name:"DUTCH", code:"nl", direction:"LTR", charset:"UTF8"},
    {name:"ENGLISH", code:"en", direction:"LTR", charset:"UTF8"},
    {name:"ESPERANTO", code:"eo", direction:"LTR", charset:"UTF8"},
    {name:"ESTONIAN", code:"et", direction:"LTR", charset:"UTF8"},
    {name:"FILIPINO", code:"tl", direction:"LTR", charset:"UTF8"},
    {name:"FINNISH", code:"fi", direction:"LTR", charset:"UTF8"},
    {name:"FRENCH", code:"fr", direction:"LTR", charset:"UTF8"},
    {name:"GALICIAN", code:"gl", direction:"LTR", charset:"UTF8"},
    {name:"GEORGIAN", code:"ka", direction:"LTR", charset:"UTF8"},
    {name:"GERMAN", code:"de", direction:"LTR", charset:"UTF8"},
    {name:"GREEK", code:"el", direction:"LTR", charset:"UTF8"},
    {name:"HEBREW", code:"iw", direction:"LTR", charset:"UTF8"},
    {name:"HINDI", code:"hi", direction:"LTR", charset:"UTF8"},
    {name:"HUNGARIAN", code:"hu", direction:"LTR", charset:"UTF8"},
    {name:"ICELANDIC", code:"is", direction:"LTR", charset:"UTF8"},
    {name:"INDONESIAN", code:"id", direction:"LTR", charset:"UTF8"},
    {name:"IRISH", code:"ga", direction:"LTR", charset:"UTF8"},
    {name:"ITALIAN", code:"it", direction:"LTR", charset:"UTF8"},
    {name:"JAPANESE", code:"ja", direction:"LTR", charset:"UTF8"},
    {name:"KOREAN", code:"ko", direction:"LTR", charset:"UTF8"},
    {name:"LATIN", code:"la", direction:"LTR", charset:"UTF8"},
    {name:"LATVIAN", code:"lv", direction:"LTR", charset:"UTF8"},
    {name:"LITHUANIAN", code:"lt", direction:"LTR", charset:"UTF8"},
    {name:"MACEDONIAN", code:"mk", direction:"LTR", charset:"UTF8"},
    {name:"MALAY", code:"ms", direction:"LTR", charset:"UTF8"},
    {name:"MALTESE", code:"mt", direction:"LTR", charset:"UTF8"},
    {name:"NORWEGIAN", code:"no", direction:"LTR", charset:"UTF8"},
    {name:"PERSIAN", code:"fa", direction:"LTR", charset:"UTF8"},
    {name:"POLISH", code:"pl", direction:"LTR", charset:"UTF8"},
    {name:"PORTUGUESE", code:"pt", direction:"LTR", charset:"UTF8"},
    {name:"ROMANIAN", code:"ro", direction:"LTR", charset:"UTF8"},
    {name:"RUSSIAN", code:"ru", direction:"LTR", charset:"UTF8"},
    {name:"SERBIAN", code:"sr", direction:"LTR", charset:"UTF8"},
    {name:"SLOVAK", code:"sk", direction:"LTR", charset:"UTF8"},
    {name:"SLOVENIAN", code:"sl", direction:"LTR", charset:"UTF8"},
    {name:"SPANISH", code:"es", direction:"LTR", charset:"UTF8"},
    {name:"SWAHILI", code:"sw", direction:"LTR", charset:"UTF8"},
    {name:"SWEDISH", code:"sv", direction:"LTR", charset:"UTF8"},
    {name:"THAI", code:"th", direction:"LTR", charset:"UTF8"},
    {name:"TURKISH", code:"tr", direction:"LTR", charset:"UTF8"},
    {name:"UKRAINIAN", code:"uk", direction:"LTR", charset:"UTF8"},
    {name:"VIETNAMESE", code:"vi", direction:"LTR", charset:"UTF8"},
    {name:"WELSH", code:"cy", direction:"LTR", charset:"UTF8"},
    {name:"YIDDISH", code:"yi", direction:"LTR", charset:"UTF8"}
  ]
};
